﻿Public Class Zone

    Property Id As Integer
    Property Owner As CountryShortName
    Property Controller As CountryShortName
    Property Core As CountryShortName
    Property Infrastructure As Infrastructure
    Property Flags As Flags
    Property Points As Integer
    Property weather As Weather
    Property OutOfSupplyDays As Integer

    Public Sub Load(stream As IO.StreamReader, zoneId As Integer)

        Dim shouldExit As Boolean = False
        Dim data As LineData

        Do Until shouldExit OrElse stream.EndOfStream
            data = ReadLineData(stream)

            Select Case data.LineType

                Case DataLineType.StartBlock
                    Select Case data.BlockName
                        Case "flags"
                            Flags = New Flags()
                            Flags.Load(stream)
                        Case "infra"
                            Infrastructure = New Infrastructure
                            Infrastructure.Load(stream)
                        Case "weather"
                            weather = New Weather
                            weather.Load(stream)
                        Case Else
                            AddUnmanagedLine(data.OriginalText)
                    End Select

                Case DataLineType.KeyValue
                    Select Case data.KeyValueData.Key
                        Case "owner"
                            Owner = Parser.CountryConverter(data.KeyValueData.Value.Text)
                        Case "controller"
                            Controller = Parser.CountryConverter(data.KeyValueData.Value.Text)
                        Case "core"
                            Core = Parser.CountryConverter(data.KeyValueData.Value.Text)

                        Case "points"
                            Points = data.KeyValueData.Value.ToInteger

                        Case "out_of_supply_days"
                            OutOfSupplyDays = data.KeyValueData.Value.ToInteger
                        Case Else
                            AddUnmanagedLine(data.OriginalText)
                    End Select
                Case DataLineType.StarBlockChar
                Case DataLineType.EndBlockChar
                    shouldExit = True
            End Select
        Loop
    End Sub

End Class
